import 'dart:convert';
import 'package:flutter_mark_trip/model/search_model.dart';
import 'package:http/http.dart' as http;

///搜索Dao层设计
class SearchDao{
  static Future<SearchModel> doSearch(String url,String text) async{
    final response = await http.get(url);
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();//fix 中文乱码
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      //标记当前搜索数据的标签
      SearchModel model =  SearchModel.fromJson(result);
      model.keyword = text;
      return model;
    }else{
      //抛出异常，加载接口数据失败时
      throw Exception('Failed to load home_page.json');
    }
  }
}